package com.ruoyi.framework.datasource

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
import javax.sql.DataSource

/**
 * 动态数据源
 *
 * @author ruoyi
 */
class DynamicDataSource(defaultTargetDataSource: DataSource?, targetDataSources: MutableMap<Any, Any>) : AbstractRoutingDataSource() {
    init {
        defaultTargetDataSource?.let { super.setDefaultTargetDataSource(it) }
        super.setTargetDataSources(targetDataSources)
        super.afterPropertiesSet()
    }

    override fun determineCurrentLookupKey(): Any? {
        println("dataSourceType取值")
        return DynamicDataSourceContextHolder.dataSourceType
    }
}
